package com.tree.leetcode.array;

import cn.hutool.json.JSONUtil;

/**
 * @ClassName com.tree.leetcode.array
 * Description: 轮转数组
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 1/27/24 4:49 PM
 * @Version 1.0
 */
public class Rotate_189 {

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6,7};
        rotate(nums,5);
    }

    public static void rotate(int[] nums, int k) {
        int n = nums.length;
        int[] newArr = new int[n];
        for (int i = 0; i < n; i++) {
            newArr[(i + k) % n] = nums[i];
        }
        System.out.println(JSONUtil.toJsonStr(newArr));
        System.arraycopy(newArr, 0, nums, 0, n);
        System.out.println(JSONUtil.toJsonStr(newArr));

    }

}
